package com.shroo8.footballblog.controllers.api;

import java.util.Locale;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.shroo8.footballblog.bo.api.UpdateArticleRatingBo;

@Controller
public class UpdateArticleRatingController {
	private static final Logger logger = LoggerFactory.getLogger(UpdateArticleRatingController.class);

	@Resource(name="updateArticleRatingBo", type=com.shroo8.footballblog.bo.api.UpdateArticleRatingBoImpl.class)
	private UpdateArticleRatingBo updateArticleRatingBo;
	
	/*
	 * using @RequestBody as a work around as spring does not support PUT with @RequestParam
	 * */
	@RequestMapping(value = "/articles/{articleId}/ratings", method = RequestMethod.POST)
	public @ResponseBody String createArticleRating(Locale locale, @PathVariable("articleId") String articleId,@RequestParam int articleRating) {
		logger.info("Welcome to createArticleRating! The client locale is {}.", locale);
		logger.info("article id is:" + articleId);

		updateArticleRatingBo.updateArticleRating(articleId, articleRating);
		return "";
	}

}
